package com.zhanghaijun.createCode.Data;

import com.zhanghaijun.createCode.util.PrintUtil;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by zhanghaijun on 15/7/27.
 */
public class DateUtil {



    public static  List<String> getDateList(String format){
        List<String> dates = new ArrayList<String>();
        for(int i=6;i>=0;i--){
            dates.add(getDate(i,format));
        }
        return dates;
    }

    /**
     * 获取前几天的日期字符串
     * @param num
     * @return
     * "yyyyMMdd"
     */
    public static String getDate(int num,String format){
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, -num);
        Date monday = c.getTime();
        String preMonday = sdf.format(monday);
        return preMonday;
    }


    









}
